package me.zhengjie.modules.quartz.task;

import com.qiaofang.applet.service.other.domain.Corporation;
import com.qiaofang.applet.service.other.domain.PropertyRules;
import com.qiaofang.applet.service.other.service.CorporationService;
import com.qiaofang.applet.service.property.service.PropertyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class V20UpDownStateBrushTask {

    @Autowired
    private CorporationService corporationService;

    @Autowired
    private PropertyService propertyService;

    public void run() {
        log.info("V20UpDownStateBrushTask run start");
        Corporation corporation = new Corporation();
        corporation.setDeleted(Boolean.FALSE);
        corporation.setV20Flag(Boolean.TRUE);
        Iterable<Corporation> list = corporationService.findAll(Example.of(corporation));
        list.forEach(item -> {
            String corporationCode = item.getCorporationCode();
            log.info("开始处理20集团:{}的上下架状态，开始时间:{}", corporationCode, new Date());
            long currentTimeMillis = System.currentTimeMillis();

            PropertyRules propertyRules = item.getPropertyRules();
            long num = propertyService.batchDownV20Property(propertyRules, corporationCode, currentTimeMillis);
            log.info("20集团:{}批量下架二手房数量:{}", corporationCode, num);
            num = propertyService.batchUpV20Property(corporationCode, currentTimeMillis);
            log.info("20集团:{}批量上架二手房数量:{}", corporationCode, num);
            log.info("完成处理集团:{}的上下架状态，完成时间:{}", corporationCode, new Date());
        });
        log.info("V20UpDownStateBrushTask run end");
    }
}
